package com.msf.common.config.redis.receiver;

import cn.hutool.core.util.ObjectUtil;
import com.msf.common.base.BaseMap;
import com.msf.common.config.redis.listener.RedisListener;
import com.msf.common.constant.CacheConstant;
import com.msf.common.utils.SpringContextUtils;
import lombok.Data;
import org.springframework.stereotype.Component;

@Component
@Data
public class RedisReceiver {
    /**
     * 接受消息并调用业务逻辑处理器
     *
     * @param params
     */
    public void onMessage(BaseMap params) {
        Object handlerName = params.get(CacheConstant.HANDLER_NAME);
        RedisListener messageListener = SpringContextUtils.getHandler(handlerName.toString(), RedisListener.class);
        if (ObjectUtil.isNotEmpty(messageListener)) {
            messageListener.onMessage(params);
        }
    }

}
